<template>
  <div class="container">
    <baleTable
      :tableData="tableData"
      :tableHead="tableHead"
      :isSearch="true"
      :isTableSelect="true"
      :tableLoading="tableLoading"
      :page="page"
      @pageSizeChange="pageSizeChange"
      @handleCurrentChange="handleCurrentChange"
      @searchMethods="searchMethods"
      @tableSortChange="tableSortChange"
      @handleRowClick="handleRowClick"
      ref="baleTable"
    >
      <template #headLeft>
        <!--   <el-button
          type="primary"
          size="small"
          @click="pharmacyDispensing()"
          >药房发药</el-button
        > -->
        <!--    <el-button size="small" type="success" @click="importData()">数据导入</el-button> -->
        <!--    <el-button size="small" type="primary" @click="showDialog('')"
          >添加</el-button
        > -->
        <!-- <div
          class="ml10 tableStats-btn tableStats-btn-active"
          @click="showDialog('')"
        >
          添加
        </div> -->
      </template>
      <template #pic="{ scope }">
        <div @click.stop="">
          <tablePrImg
            v-if="scope.row.pic"
            :imgSrc="scope.row.pic"
            :prImgList="[scope.row.pic]"
          />
        </div>
      </template>

      <!-- 机构名称 -->
      <template #unit_id="{ scope }">
        {{ formatterUnitId(scope.row.unit_id) }}
      </template>

      <template #consultation_type="{ scope }">
        {{ formatterConsultationType(scope.row.consultation_type) }}
      </template>

      <!-- 等级 -->
      <template #skill="{ scope }">
        {{ formmateSkill(scope.row.skill) }}
      </template>
  <template #medical="{ scope }">
        <div class="mb5" v-for="item in JSON.parse(scope.row.medical)" :key="item.id">
          <el-popover trigger="hover" placement="top">
            <p>单价: {{item.price }}</p>
            <p>药品规格: {{item.size }}</p>
           <!--  <p>频率(次): {{item.doseFrequency }}</p>
            <p>用药天数(天): {{item.days }}</p> -->
            <p>剂量: {{item.dosage }}</p>
       <!--      <p>注意事项: {{item.precautions }}</p> -->
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ item.name }}</el-tag>
            </div>
          </el-popover>
        </div>
      </template>
      <!--    操作 -->
    
            <template #tableOperation="{ scope }">
      
         <el-button type="primary" v-if="scope.row.review_result=='通过'" size="mini" @click="pharmacyDispensing(scope.row)"
          >药品配送</el-button
        >
      </template>
       
      <template #second_review_result="{ scope }">
        {{scope.row.second_review_result=='1'?'通过':'不通过'}}
      </template>

    </baleTable>

    <!--   <userList ref="userListDialog"></userList> -->
    <basicDialog ref="basicDialog" />
  </div>
</template>

<script>
import { ApigetMedicine, ApiMedicineDel } from "@a/index";
import { tableHead } from "./config";
import basicDialog from "./component/basicDialog.vue";
export default {
  components: { basicDialog },
  data() {
    return {
      tableHead,
      tableData: [
        {
          ICD: "炭疽",
          ICD1: "炭疽",
          created_at: "2025-03-12 13:53:53",
          disease: "炭疽",
          doctor_id: 2,
          doctor_name: "张三",
          review_name: "白居易",
          review_result: 1,
          review_time: "2025-03-12 13:54:14",
          review_uid: 5,
          id: 15,
          invalid: 0,
          main: "21321321",
          medical:
            '[{"id":3,"type":"非处方药","pic":"files/admin/20241217/20241217121933_感冒清.jpg","name":"感冒清胶囊","common_name":"感冒清胶囊","price":"15.00","introduce":"--","size":"30粒/瓶","ingredient":"--","feature":"感冒、发烧、流鼻涕","save":"常温储存","note":"对本品过敏者禁用","guide":"口服。一次一片，一日三次","created_at":"2024-12-17 12:21:51","updated_at":"2024-12-17 12:22:09","checkStep":false,"count":"1","doseFrequency":"2","days":"2","precautions":"11","num":"2"}]',
          not_pass_reason: null,
          order_id: 122,
          patient: {
            id: 6,
            uid: 1,
            relation: "本人",
            name: "程文",
            card_type: "居民身份证",
            card_no: "410522199702079351",
          },
          area: "湖北省-荆州市-京山市",
          area_detail: "洪山万科广场1",
          birth: "1997-02-07",
          card_file: "",
          card_no: "410522199702079351",
          card_type: "居民身份证",
          created_at: "2024-12-03 14:12:31",
          gender: "男",
          id: 6,
          medical_card: "",
          name: "程文",
          nation: "汉",
          phone: "13164640637",
          relation: "本人",
          uid: 1,
          updated_at: "2025-03-13 09:37:14",
          use: 1,
          patient_id: 6,
          second_review_name: "李白",
          second_review_result: 1,
          second_review_time: "2025-03-12 13:54:32",
          second_review_uid: 6,
          status: "未使用",
          type: "麻风",
          uid: 1,
          updated_at: "2025-03-12 13:54:32",
          use: 0,
        },
      ],
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      tableLoading: false,
      searchParams: {},
      sortParams: {},
      editFormVisible: false,
      btnLoading: false,
      unitList: [],
      subDepartMentArr: [],
      consultation_typeArr: [
        { name: "全部", code: "0" },
        { name: "图文问诊", code: "1" },
        { name: "视频问诊", code: "2" },
      ],
    };
  },
  mounted() {
    this.getTableData();
  },

  methods: {
    pharmacyDispensing() {
      this.$refs.basicDialog.show();
    },
    formatterConsultationType(val) {
      let data = this.consultation_typeArr.find((item) => {
        if (item.code == val) {
          return item;
        }
      });

      if (data) {
        return data.name;
      } else {
        return val;
      }
    },

    importData() {
      this.$refs.importData.show();
    },

    //编辑界面
    onEdit() {},
    showDialog(val) {
      this.$refs.dialognur.show(val);
    },
    /*    userList(id) {
      this.$router.push({
        name: "detail",
        params: { id },
      });
    }, */
    getTableData(params = {}) {
      let postParams = {
        ...params,
        ...this.searchParams,
        ...this.sortParams,
        ...this.page,
      };
      /*    this.tableLoading = true; */
      /*  ApigetMedicine(postParams).then((res) => {
        let { data, page } = res;
        this.tableData = data;
        this.page.total = page.total;
        this.tableLoading = false;
      }); */
    },
    searchMethods(params) {
      this.searchParams = {};
      this.page.page = 1;
      this.searchParams = params;
      this.getTableData();
    },
    pageSizeChange(val) {
      this.page.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTableData();
    },
    tableSortChange(params) {
      if (params.sort_str) {
        this.sortParams = { ...this.sortParams, ...params };
      } else {
        delete this.sortParams.sort_str;
        delete this.sortParams.sort_order;
      }
      this.page.page = 1;
      this.getTableData();
    },

    handleRowClick(params) {},
    //shanchu
    deList(id) {
      this.$confirm("是否删除该数据项?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          ApiMedicineDel(id).then((res) => {
            this.$message.success("操作成功！");
            this.getTableData();
          });
        })
        .catch((err) => {});
    },

    /*    resetButton(id) {
         this.$confirm("是否确认重置密码?", "提示", {
           confirmButtonText: "确定",
           cancelButtonText: "取消",
           center: true,
           type: "warning",
         })
           .then((res) => {
             ApiResetPassword(id).then((res) => {
               this.$alert("重置成功，该员工初始密码为：123456", "提示", {
                 confirmButtonText: "确定",
                 callback: (action) => { },
               });
               this.getTableData();
             });
           })
           .catch((err) => { });
       }, */
  },
  filters: {},
};
</script>

<style lang="less" scoped></style>
